package Demo1;

import java.util.PriorityQueue;
class Student{
    public String name;

    @Override
    public boolean equals(Object obj) {
         Student o = (Student) obj;
         //调用String的equals方法
         return o.name.equals(this.name);
    }

}
public class Test {
    public static void main(String[] args) {
        Student student1 = new Student();
        student1.name = "zhangsan";
        Student student2 = new Student();
        student2.name = "zhangsan";
        System.out.println(student1 == student2);//比较地址
        System.out.println(student1.equals(student2));//不重写也默认比较地址
    }
    public static void main2(String[] args) {
        TestHeap testHeap = new TestHeap();
        int[] array = {27,15,19,18,28,34,65,49,25,37};
        testHeap.initHeap(array);
        testHeap.creatHeap();
        testHeap.heapSort();
    }
    //求第k大的元素
    public static int maxK(int[] arr,int k){
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        for (int i = 0; i < k; i++) {
            priorityQueue.offer(arr[i]);
        }
        for (int i = k; i < arr.length; i++) {
            if(arr[i] > priorityQueue.peek()){
                priorityQueue.poll();
                priorityQueue.offer(arr[i]);
            }
        }
        return priorityQueue.peek();
    }
    public static void main1(String[] args) {
        int[] arr = {12,23,34,45,56,67,78,89};
        System.out.println(maxK(arr, 3));
    }
}
